package com.ybkj.chat.ui.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ybkj.chat.R;

/**
 * author : ywh
 * date : 2019/1/28 15:17
 * description :
 */
public class MoreTextView extends RelativeLayout {
    //左边字体
    private TextView leftTv;
    // 中间字体
    private TextView centerTv;
    //右边字体
    private TextView rightTv;
    //左边字体大小
    private int leftSize;
    //中间字体大小
    private int centerSize;
    //右边字体大小
    private int rightSize;
    //左边字体颜色
    private int leftColor;
    //中间字体颜色
    private int centerColor;
    //右边字体颜色
    private int rightColor;
    //中间字体距离左边的距离
    private int centerPaddingLeft;
    //中间字体距离右边字体的距离
    private int centerPaddingRight;

    public MoreTextView(Context context) {
        super(context);
    }

    public MoreTextView(Context context, AttributeSet attrs) {
        super(context, attrs);

        // 加载布局
        LayoutInflater.from(context).inflate(R.layout.layout_more_view, this);
        // 获取控件
        leftTv = findViewById(R.id.left_text);
        centerTv = findViewById(R.id.center_text);
        rightTv = findViewById(R.id.right_text);
        getAttrs(context, attrs);
    }

    private void getAttrs(Context context, AttributeSet attrs) {
        if (attrs != null) {
            TypedArray mTypedArray = context.obtainStyledAttributes(attrs, R.styleable.moreTextView);
            //字体大小
            leftSize = mTypedArray.getDimensionPixelSize(R.styleable.moreTextView_leftTextSize, 0);
            centerSize = mTypedArray.getDimensionPixelSize(R.styleable.moreTextView_centerTextSize, 0);
            rightSize = mTypedArray.getDimensionPixelSize(R.styleable.moreTextView_rightTextSize, 0);
            leftTv.setTextSize(leftSize);
            centerTv.setTextSize(centerSize);
            rightTv.setTextSize(rightSize);
            //字体颜色
            leftColor = mTypedArray.getColor(R.styleable.moreTextView_leftColor, 0);
            centerColor = mTypedArray.getColor(R.styleable.moreTextView_centerColor, 0);
            rightColor = mTypedArray.getColor(R.styleable.moreTextView_rightColor, 0);
            leftTv.setTextColor(leftColor);
            centerTv.setTextColor(centerColor);
            rightTv.setTextColor(rightColor);
            //间距
            centerPaddingLeft = mTypedArray.getDimensionPixelSize(R.styleable.moreTextView_centerPaddingLeft, 0);
            centerPaddingRight = mTypedArray.getDimensionPixelSize(R.styleable.moreTextView_centerPaddingRight, 0);
            centerTv.setPadding(centerPaddingLeft, 0, centerPaddingRight, 0);
        }
    }

    /**
     * 设置左边字体
     *
     * @param leftTextView
     */
    public void setLeftTextView(String leftTextView) {
        leftTv.setText(leftTextView);
    }

    /**
     * 设置中间字体
     *
     * @param centerTextView
     */
    public void setCenterTextView(String centerTextView) {
        centerTv.setText(centerTextView);
    }

    /**
     * 设置右边字体
     *
     * @param rightTextView
     */
    public void setRightTextView(String rightTextView) {
        rightTv.setText(rightTextView);
    }

    /**
     * 设置左边字体颜色
     *
     * @param color
     */
    public void setLeftColor(int color) {
        leftTv.setTextColor(color);
    }

    /**
     * 设置中间字体颜色
     *
     * @param color
     */
    public void setCenterColor(int color) {
        centerTv.setTextColor(color);
    }

    /**
     * 设置右边字体颜色
     *
     * @param color
     */
    public void setRightColor(int color) {
        rightTv.setTextColor(color);
    }

    /**
     * 设置中间字体的距离边距
     *
     * @param left
     * @param top
     * @param right
     * @param bottom
     */
    public void setCenterPadding(int left, int top, int right, int bottom) {
        centerTv.setPadding(left, top, right, bottom);
    }
}